// pages/shopcar/shopcar.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    goodlistLists:{
      goods1:[
        {goods_src:"https://6c72-lrz-3gq6bcnl0434c93b-1304045771.tcb.qcloud.la/lucking/shopcar/bottom1.png?sign=8b021f311bd1a06ade6bfaa6431b96a2&t=1608186857",goods_title:"姜饼人拿铁",
        goods_english:"Christmas",goods_price:"￥17.05",
      },
        {goods_src:"https://6c72-lrz-3gq6bcnl0434c93b-1304045771.tcb.qcloud.la/lucking/shopcar/bottom2.png?sign=e3bffb48ef647d273e2735ded446b1c1&t=1608186919",goods_title:"标准美式",
        goods_english:"Americano",goods_price:"￥13"
      },
        {goods_src:"https://6c72-lrz-3gq6bcnl0434c93b-1304045771.tcb.qcloud.la/lucking/shopcar/bottom3.png?sign=ee6fbddab97f48646166675e5164e4e2&t=1608186941",goods_title:"焦糖拿铁",
        goods_english:"Caramel Latte",goods_price:"￥16.8"
      },
        {goods_src:"https://6c72-lrz-3gq6bcnl0434c93b-1304045771.tcb.qcloud.la/lucking/shopcar/bottom4.png?sign=78211eadda241a17bf785562ddf72094&t=1608186955",goods_title:"拿铁",
        goods_english:"Latte",goods_price:"￥13.75"
      },
        {goods_src:"https://6c72-lrz-3gq6bcnl0434c93b-1304045771.tcb.qcloud.la/lucking/shopcar/bottom5.png?sign=955decf9c2962f621ebf9a98339fb231&t=1608186970",goods_title:"冲绳黑糖拿铁",
        goods_english:"Brown Sugar Latte",goods_price:"￥15.4"
      },
        {goods_src:"https://6c72-lrz-3gq6bcnl0434c93b-1304045771.tcb.qcloud.la/lucking/shopcar/bottom6.png?sign=7ed72a1fadc4371065299447c126bc0a&t=1608186986",goods_title:"焦糖玛奇朵",
        goods_english:"Caramel Macchiato",goods_price:"￥19"
      },
    ]
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
   // 统计功能实现
   tiaozhuan:function(e){
     console.log("按钮")
    wx.switchTab({
      url: '/pages/list/list',
    })
   },
   jiesuan:function(e){
    wx.navigateTo({
      url: '/pages/pay/pay',
    })
   },
  onLoad: function (options) {
    
    console.log(app.globalData.arr.length)
    
    var zong=0
    for (const key in this.data.shopcar) {
      zong=zong+((this.data.shopcar)[key].val)*((this.data.shopcar)[key].price).substring(1)
     console.log(zong)
    }
    
    this.setData({
      shopcar:app.globalData.arr,
      zongjiage:zong
    })
    app.globalData.alljiage=this.data.zongjiage
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  tiaozhuan:function(){
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log(app.globalData.arr.length)
    
    var zong=0
    for (const key in this.data.shopcar) {
      zong=zong+((this.data.shopcar)[key].val)*((this.data.shopcar)[key].price).substring(1)
     console.log(zong)
    }
    
    this.setData({
      shopcar:app.globalData.arr,
      zongjiage:zong
    })
    app.globalData.alljiage=this.data.zongjiage
  
  },
  // 实现加减功能
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})